package com.sun.module_common.widget

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Search
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.sun.module_base.ext.click
import com.sun.module_base.theme.color_333
import com.sun.module_base.theme.color_666
import com.sun.module_base.theme.color_999
import com.sun.module_base.theme.white1

/**
 *@author:sunc
 *@time :2025/8/13 11:02
 *@desc: 描述  自定义输入框
 */
@Composable
fun SearchTextField(modifier: Modifier = Modifier) {
    var text by remember { mutableStateOf("") }
    var iconColor by remember { mutableStateOf(color_999) }
    var textColor by remember { mutableStateOf(color_999) }
    BasicTextField(
        modifier = modifier then Modifier
            .click {
                iconColor = color_666
                textColor = color_333
            }
            .fillMaxWidth(),
        value = text,
        onValueChange = { text = it },
        textStyle = TextStyle(color = textColor, fontSize = 12.sp),
        decorationBox = {
            Row(
                verticalAlignment = Alignment.CenterVertically,
                modifier = Modifier
                    .background(white1, shape = RoundedCornerShape(10.dp))
                    .border(width = 1.dp, color = color_666, shape = RoundedCornerShape(10.dp))
                    .padding(horizontal = 5.dp)
            ) {
                Icon(
                    imageVector = Icons.Default.Search,
                    contentDescription = null,
                    tint = iconColor
                )
                Box(contentAlignment = Alignment.CenterStart) {
                    if (text.isEmpty()) { //提示语
                        Text(text = "全网搜索", fontSize = 12.sp, color = textColor)
                    }
                    it()
                }
            }
        })
}